home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 2000 August: Tool Chest / Dev.CD Aug 00 TC Disk 2.toast / pc / sample code / quicktime / all macintosh / quicktime for java / musicmixer / src / musicmixer.java
Encoding:
Java Source  |  2000-06-23  |  2.5 KB  |  92 lines

  1. /*
  2.  * QuickTime for Java SDK Sample Code
  3.  
  4.    Usage subject to restrictions in SDK License Agreement
  5.  * Copyright: © 1996-1999 Apple Computer, Inc.
  6.  
  7.  */
  8. import java.awt.*;
  9. import java.awt.event.*;
  10. import java.util.*;
  11. import javax.swing.*;
  12.  
  13. import quicktime.*;
  14. import quicktime.app.QTFactory;
  15. import quicktime.app.players.*;
  16. import quicktime.app.display.*;
  17. import quicktime.app.audio.*;
  18. import quicktime.io.*;
  19. import quicktime.std.*;
  20. import quicktime.std.movies.*;
  21. import quicktime.std.movies.media.*;
  22.  
  23. import mixer.*;
  24. import mixer.display.*;
  25. import mixer.mc.*;
  26.  
  27. /** This is the main class in our Mixer.  It will display a window with the movie
  28.  *  and create a mixer to control the movie from.
  29.  */
  30. public final class MusicMixer extends JFrame {
  31.     private QTCanvas myCanvas;
  32.     private QTPlayer myPlayer;
  33.     private MixerDialog myMixer;
  34.     
  35.     public static void main (String args[]) {
  36.         try {
  37.             QTSession.open();
  38.  
  39.             Frame f = new MusicMixer("Movie");
  40.             f.setVisible(true);
  41.             f.toFront();
  42.         }
  43.         catch (Exception e) {
  44.             e.printStackTrace();
  45.         }
  46.     }
  47.     
  48.     /** The constructor opens a movie, creates a window to display it in, and then
  49.      *  creates the mixer with the movie.
  50.      *  @param name the name of the window with the movie in it
  51.      */
  52.     public MusicMixer(String name) throws Exception {
  53.         super(name);
  54.  
  55.         Container cp = getContentPane();
  56.         cp.setLayout(null);
  57.                 
  58.         QTFile movieFile = new QTFile (QTFactory.findAbsolutePath ("AudioMIDI.mov"));
  59.         OpenMovieFile infile = OpenMovieFile.asRead(movieFile);
  60.         Movie myMovie = Movie.fromFile(infile);
  61.         infile.close();
  62.         
  63.         // prepare to show movie
  64.         myCanvas = new QTCanvas();
  65.         cp.add(myCanvas);
  66.         addNotify();
  67.         MovieController mc = new MovieController(myMovie);
  68.         Insets insets = getInsets();
  69.         setBounds(0, 0, (insets.left + insets.right + mc.getBounds().getWidth()),
  70.                                         (insets.top + insets.bottom + mc.getBounds().getHeight()));
  71.         myPlayer = new QTPlayer(mc);
  72.         myCanvas.setClient(myPlayer, true);
  73.         
  74.         // build up the mixer control panel
  75.         MixerDialog.parentFrame = this;
  76.         MixerDialog.defaultName = "Mix:" + movieFile.getName();
  77.         myMixer = new MixerDialog (new MasterDisplay (new MixerMovie (myPlayer)));
  78.         
  79.         // add the window listener to the main window
  80.         addWindowListener(new WindowAdapter() {
  81.             public void windowClosing (WindowEvent e) {
  82.                 myCanvas.removeClient();
  83.                 QTSession.close();
  84.                 dispose();
  85.             }
  86.             
  87.             public void windowClosed (WindowEvent e) {
  88.                 System.exit(0);
  89.             }
  90.         });
  91.     }
  92. }